//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.imagemanager.util;

import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Bitmap.Config;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.webkit.MimeTypeMap;
import java.io.Closeable;

public class Util {
    private static final String TAG = "db.Util";
    private static final String MAPS_PACKAGE_NAME = "com.google.android.apps.maps";
    private static final String MAPS_CLASS_NAME = "com.google.android.maps.MapsActivity";

    private Util() {
    }

    public static Bitmap rotate(Bitmap b, int degrees) {
        if(degrees != 0 && b != null) {
            Matrix m = new Matrix();
            m.setRotate((float)degrees, (float)b.getWidth() / 2.0F, (float)b.getHeight() / 2.0F);

            try {
                Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);
                if(b != b2) {
                    b.recycle();
                    b = b2;
                }
            } catch (OutOfMemoryError var4) {
                ;
            }
        }

        return b;
    }

    public static Bitmap transform(Matrix scaler, Bitmap source, int targetWidth, int targetHeight, boolean scaleUp) {
        int deltaX = source.getWidth() - targetWidth;
        int deltaY = source.getHeight() - targetHeight;
        int dx1;
        int dy1;
        if(scaleUp || deltaX >= 0 && deltaY >= 0) {
            float bitmapWidthF = (float)source.getWidth();
            float bitmapHeightF = (float)source.getHeight();
            float bitmapAspect = bitmapWidthF / bitmapHeightF;
            float viewAspect = (float)targetWidth / (float)targetHeight;
            float scale;
            if(bitmapAspect > viewAspect) {
                scale = (float)targetHeight / bitmapHeightF;
                if(scale >= 0.9F && scale <= 1.0F) {
                    scaler = null;
                } else {
                    scaler.setScale(scale, scale);
                }
            } else {
                scale = (float)targetWidth / bitmapWidthF;
                if(scale >= 0.9F && scale <= 1.0F) {
                    scaler = null;
                } else {
                    scaler.setScale(scale, scale);
                }
            }

            Bitmap b1;
            if(scaler != null) {
                b1 = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), scaler, true);
            } else {
                b1 = source;
            }

            dx1 = Math.max(0, b1.getWidth() - targetWidth);
            dy1 = Math.max(0, b1.getHeight() - targetHeight);
            Bitmap b2 = Bitmap.createBitmap(b1, dx1 / 2, dy1 / 2, targetWidth, targetHeight);
            if(b1 != source) {
                b1.recycle();
            }

            return b2;
        } else {
            Bitmap b2 = Bitmap.createBitmap(targetWidth, targetHeight, Config.ARGB_8888);
            Canvas c = new Canvas(b2);
            int deltaXHalf = Math.max(0, deltaX / 2);
            int deltaYHalf = Math.max(0, deltaY / 2);
            Rect src = new Rect(deltaXHalf, deltaYHalf, deltaXHalf + Math.min(targetWidth, source.getWidth()), deltaYHalf + Math.min(targetHeight, source.getHeight()));
            dx1 = (targetWidth - src.width()) / 2;
            dy1 = (targetHeight - src.height()) / 2;
            Rect dst = new Rect(dx1, dy1, targetWidth - dx1, targetHeight - dy1);
            c.drawBitmap(source, src, dst, (Paint)null);
            return b2;
        }
    }

    public static Bitmap extractMiniThumb(Bitmap source, int width, int height) {
        return extractMiniThumb(source, width, height, true);
    }

    public static Bitmap extractMiniThumb(Bitmap source, int width, int height, boolean recycle) {
        if(source == null) {
            return null;
        } else {
            float scale;
            if(source.getWidth() < source.getHeight()) {
                scale = (float)width / (float)source.getWidth();
            } else {
                scale = (float)height / (float)source.getHeight();
            }

            Matrix matrix = new Matrix();
            matrix.setScale(scale, scale);
            Bitmap miniThumbnail = transform(matrix, source, width, height, false);
            if(recycle && miniThumbnail != source) {
                source.recycle();
            }

            return miniThumbnail;
        }
    }

    public static <T> int indexOf(T[] array, T s) {
        for(int i = 0; i < array.length; ++i) {
            if(array[i].equals(s)) {
                return i;
            }
        }

        return -1;
    }

    public static void closeSilently(Closeable c) {
        if(c != null) {
            try {
                c.close();
            } catch (Throwable var2) {
                ;
            }

        }
    }

    public static void closeSilently(ParcelFileDescriptor c) {
        if(c != null) {
            try {
                c.close();
            } catch (Throwable var2) {
                ;
            }

        }
    }

    public static void Assert(boolean cond) {
        if(!cond) {
            throw new AssertionError();
        }
    }

    public static boolean equals(String a, String b) {
        return a == b || a.equals(b);
    }

    public static Intent createSetAsIntent(Uri uri, String mimeType) {
        if(uri.getScheme().equals("file")) {
            String path = uri.getPath();
            int lastDotIndex = path.lastIndexOf(46);
            if(lastDotIndex != -1) {
                mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(uri.getPath().substring(lastDotIndex + 1).toLowerCase());
            }
        }

        Intent intent = new Intent("android.intent.action.ATTACH_DATA");
        intent.setDataAndType(uri, mimeType);
        intent.putExtra("mimeType", mimeType);
        return intent;
    }

    public static void openMaps(Context context, double latitude, double longitude) {
        Intent mapsIntent;
        try {
            String url = String.format("http://maps.google.com/maps?f=q&q=(%s,%s)", new Object[]{Double.valueOf(latitude), Double.valueOf(longitude)});
            ComponentName compName = new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            mapsIntent = (new Intent("android.intent.action.VIEW", Uri.parse(url))).setComponent(compName);
            context.startActivity(mapsIntent);
        } catch (ActivityNotFoundException var8) {
            Log.e("db.Util", "GMM activity not found!", var8);
            String url = String.format("geo:%s,%s", new Object[]{Double.valueOf(latitude), Double.valueOf(longitude)});
            mapsIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));
            context.startActivity(mapsIntent);
        }

    }
}
